1

Example

The following example shows how to apply the effect. OpacityMask-example.qml example

*/ Item id: rootItem

/*! This property defines the source item that is going to be masked.

It is not supported to let the effect include itself, for instance by setting source to the effect's parent. */ property variant source

/*! This property defines the item that is going to be used as the mask. The mask item gets rendered into an intermediate pixel buffer and the alpha values from the result are used to determine the source item's pixels visibility in the display.

Original Mask Effect applied Original_bug.png OpacityMask_mask.png OpacityMask_bug.png */ property variant maskSource

/*! This property allows the effect output pixels to be cached in order to improve the rendering performance.

Every time the source or effect properties are changed, the pixels in the cache must be updated. Memory consumption is increased, because an extra buffer of memory is required for storing the effect output.

It is recommended to disable the cache when the source or the effect properties are animated.

By default, the property is set to f̧alse.

It is not supported to let the effect include itself, for instance by setting maskSource to the effect's parent. */ property bool cached: false

SourceProxy id: sourceProxy input: rootItem.source

SourceProxy id: maskSourceProxy input: rootItem.maskSource

ShaderEffectSource id: cacheItem anchors.fill: parent visible: rootItem.cached smooth: true sourceItem: shaderItem live: true hideSource: visible

ShaderEffect id: shaderItem property variant source: sourceProxy.output property variant maskSource: maskSourceProxy.output

anchors.fill: parent

fragmentShader: " varying highp vec2 qt_TexCoord0; uniform highp float qt_Opacity; uniform lowp sampler2D source; uniform lowp sampler2D maskSource; void main(void) gl_FragColor = texture2D(source, qt_TexCoord0.st) * (texture2D(maskSource, qt_TexCoord0.st).a) * qt_Opacity; "